class Solution
{
public:
    vector<int> frequencySort(vector<int> &nums)
    {
        vector<vector<int>> freq(201);
        for (int i = -100; i <= 100; ++i)
        {
            freq[i + 100] = {0, i};
        }
        for (int num : nums)
        {
            ++freq[num + 100][0];
        }
        sort(freq.begin(), freq.end(), FrequencyComparator());
        vector<int> result;
        for (auto &f : freq)
        {
            if (f[0] == 0)
            {
                continue;
            }
            result.insert(result.end(), f[0], f[1]);
        }
        return result;
    }

    class FrequencyComparator
    {
    public:
        bool operator()(const vector<int> &f1, const vector<int> &f2)
        {
            if (f1[0] != f2[0])
            {
                return f1[0] < f2[0];
            }
            return f1[1] > f2[1];
        }
    };
};